package com.afd.ozblip.util;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;

/**
 * 流工具类
 * 
 * @author 徐鹏
 * 
 */
public class StreamUtil {

	/**
	 * 输出流转byte数组
	 * 
	 * @param paramInputStream
	 *            输入流参数
	 * @return
	 * @throws IOException
	 */
	public static byte[] receiveData(InputStream paramInputStream) throws IOException {
		byte[] arrayOfByte1 = null;
		// 获取字节数组输出流
		ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
		try {
			arrayOfByte1 = new byte[1024];
			int ch;
			while ((ch = paramInputStream.read()) != -1) {
				localByteArrayOutputStream.write(ch);
			}
			arrayOfByte1 = localByteArrayOutputStream.toByteArray();
			// 关闭流
			close(paramInputStream);
			close(localByteArrayOutputStream);
		} catch (Exception e) {
			arrayOfByte1 = null;
		}
		return arrayOfByte1;
	}

	/**
	 * 关闭流
	 * 
	 * @param paramCloseable
	 */
	public static void close(Closeable paramCloseable) {
		try {
			if (paramCloseable != null) {
				paramCloseable.close();
			}
		} catch (IOException localIOException) {
			localIOException.printStackTrace();
		}
	}
}
